package com.hansheng.action.material;

import com.alibaba.fastjson.JSONArray;
import com.hansheng.service.impl.MaterialServiceImpl;
import com.hansheng.util.JsonHelper;
import com.hansheng.util.PrintWriterHelper;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by GoldenMan on 2017/5/29.
 */
public class GetFatherMaterialListAction extends ActionSupport implements ServletResponseAware, ServletRequestAware {
    private HttpServletResponse httpServletResponse;
    private HttpServletRequest httpServletRequest;
    private MaterialServiceImpl materialService;

    public void setMaterialService(MaterialServiceImpl materialService) {
        this.materialService = materialService;
    }

    @Override
    public void setServletRequest(HttpServletRequest request) {
        this.httpServletRequest = request;
    }

    @Override
    public void setServletResponse(HttpServletResponse response) {
        this.httpServletResponse = response;
        httpServletResponse.setContentType("text/html;charset=utf-8");
        httpServletResponse.setHeader("Cache-Control", "no-cache");
        httpServletResponse.setHeader("Access-Control-Allow-Origin", "*");
    }

    @Override
    public String execute() throws Exception {
        // Created by GoldenMan at 2017/7/7    TODO:获取上级材质列表
        JSONArray jsonArray = materialService.getFatherMaterialList();
        PrintWriterHelper.send(JsonHelper.successJSONBuilder(jsonArray));
        return null;
    }


}
